import 'package:flutter/material.dart';

class SearchPage extends StatefulWidget {
  @override
  _SearchPage createState() => _SearchPage();
}

class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin {
  int count = 0;

  void add() {
    setState(() {
      count++;
    });
  }

  @override
  bool get wantKeepAlive => true;

  @override
  void initState() {
    super.initState();
    print('SearchPage initState');
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
        appBar: AppBar(
          //titleSpacing: 0.0,//title widget两边不留间隙
          automaticallyImplyLeading: false,
          elevation: 0, //默认是4， 设置成0 就是没有阴影了
          //导航栏
          title: Container(
            height: 45,
            child: TextField(
              style: TextStyle(
                fontSize: 18,
                textBaseline: TextBaseline.alphabetic,
              ),
              decoration: InputDecoration(
                contentPadding: EdgeInsets.zero,
                prefixIcon: Icon(
                  Icons.search,
                  color: Colors.black,
                  size: 30.0,
                ),
                fillColor: Color(0x30cccccc),
                filled: true,
                hintText: '请输入搜索内容',
                hintStyle: TextStyle(
                  height: 1.5,
                ),
                enabledBorder: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(20),
                ),
                focusedBorder: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(20),
                ),
              ),
            ),
          ),
        ),
        body: Column(children: <Widget>[
          /*
          Container(
            height: 50,
            color: Colors.red,
          ),
          */
          Expanded(
            child: ListView.separated(
              itemBuilder: (BuildContext context, int index) {
                return Container(
                  padding: const EdgeInsets.all(25.0),
                  child: Text('Item$index'),
                );
              },
              separatorBuilder: (BuildContext context, int index) {
                return Divider();
              },
              itemCount: 50,
            ),
          ),
        ]),
        floatingActionButton: FloatingActionButton(
          heroTag: 'searchFloatingActionButton',
          onPressed: add,
          child: Icon(Icons.add),
        ));
  }
}
